package com.dynamic.idea.quick.develop.plugin.entity.base02;

import cn.hutool.core.io.file.PathUtil;
import com.dynamic.idea.quick.develop.plugin.constants.QuickDevelopConstants;
import com.dynamic.idea.quick.develop.plugin.utils.FilePathUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 项目结构
 */
public class GeneralProjectStruct implements Serializable {

    /**
     * 所属父项目,根目录为空
     */
    private GeneralProjectStruct parentProjectStruct;

    /**
     * 子项目结构映射
     */
    private Map<String,GeneralProjectStruct> childProjectStructMap;

    /**
     * 项目根节点路径
     */
    private String rootPath;

    /**
     * 项目名
     */
    private String name;


    /**
     * java资源目录,默认 src/main/java,若没有java资源文件 则为空
     */
    private String srcMainJava="src"+ QuickDevelopConstants.FILE_SEPARATOR +"main"+QuickDevelopConstants.FILE_SEPARATOR+"java";

    /**
     * resources资源目录, 默认 src/main/resources 若没有resource资源文件 则为空
     */
    private String srcMainResources="src"+ QuickDevelopConstants.FILE_SEPARATOR +"main"+QuickDevelopConstants.FILE_SEPARATOR+"resources";

    /**
     * java或MapperXML的基础包名,例如 cn.sdpjw.order
     */
    private String baseJavaPackageName;

    /**
     * 资源文件的基础包
     */
    private String baseResourcePackageName;

    /**
     * 得到当前项目srcMainJava的绝对地址
     * @return
     */
    public String getSrcMainJavaPath(){
        if (StringUtils.isBlank(srcMainJava)){
            return null;
        }
        return FilePathUtils.connectPath(getRootPath(),srcMainJava);
    }

    /**
     * 得到当前项目srcMainResources的绝对地址
     * @return
     */
    public String getSrcMainResourcesPath(){
        if (StringUtils.isBlank(srcMainResources)){
            return null;
        }
        return FilePathUtils.connectPath(getRootPath(),srcMainResources);
    }

    /**
     * 得到根目录到当前目录的名字，中间用:分隔
     * @return
     */
    public String getRoot2NowProjectName(){
        if (parentProjectStruct==null){
            return name;
        }
        return parentProjectStruct.getRoot2NowProjectName()+":"+name;
    }

    // get/set方法

    public GeneralProjectStruct getParentProjectStruct() {
        return parentProjectStruct;
    }

    public void setParentProjectStruct(GeneralProjectStruct parentProjectStruct) {
        this.parentProjectStruct = parentProjectStruct;
    }

    public Map<String, GeneralProjectStruct> getChildProjectStructMap() {
        return childProjectStructMap;
    }

    public void setChildProjectStructMap(Map<String, GeneralProjectStruct> childProjectStructMap) {
        this.childProjectStructMap = childProjectStructMap;
    }

    public String getRootPath() {
        if (this.parentProjectStruct==null){
            if (StringUtils.isBlank(rootPath)){
                rootPath=null;
            }
            return rootPath;
        }
        if (StringUtils.isBlank(rootPath)){
            rootPath = this.parentProjectStruct.getRootPath();
        }
        rootPath=FilePathUtils.connectPath(rootPath,name);
        return rootPath;
    }

    public void setRootPath(String rootPath) {
        this.rootPath = rootPath;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSrcMainJava() {
        return srcMainJava;
    }

    public void setSrcMainJava(String srcMainJava) {
        this.srcMainJava = srcMainJava;
    }

    public String getSrcMainResources() {
        return srcMainResources;
    }

    public void setSrcMainResources(String srcMainResources) {
        this.srcMainResources = srcMainResources;
    }

    public String getBaseJavaPackageName() {
        return baseJavaPackageName;
    }

    public void setBaseJavaPackageName(String baseJavaPackageName) {
        this.baseJavaPackageName = baseJavaPackageName;
    }

    public String getBaseResourcePackageName() {
        return baseResourcePackageName;
    }

    public void setBaseResourcePackageName(String baseResourcePackageName) {
        this.baseResourcePackageName = baseResourcePackageName;
    }
}
